<?php

		$page = (int) $_POST['page'];
		
		if(!$page || $page == 0){
			echo json_encode(array('error'=>'Có lỗi xảy ra, vui lòng thử lại.'));
			exit();
		}
		
		$alias = $_POST['alias'];
		$array=explode("_",$alias);
		$vl=$array[1];
		switch ($vl){
			case 'pick':
				$cache=new cache;
				$_GET['page'] = (int) $_POST['page'];
				
				$sql ="select id from truyen  where pick = 1 and duyet=1 order by time_update desc ";
				$sql2="select id from truyen where pick = 1 ";
			
				$pager = new Pagination2($sql,6,4,'',0,"truyen_1");
				$pager->setDebug(false);
				$data['pick'] = $pager->paginate($cache,$sql2);
				
			
				if(!$data['pick']){
					echo json_encode(array('error'=>'Hết dữ liệu!'));
					exit();
				}

				echo json_encode(array('content'=>truyen_render_desktop_items($data['pick'])));
				break;
				
				case 'new':
				$cache=new cache;
				$_GET['page'] = (int) $_POST['page'];
				$sql ="select id from truyen  where duyet=1 order by id desc ";
				$sql2="select id from truyen where duyet = 1 ";
			
				$pager = new Pagination2($sql,6,4,'',0,"truyen_1");
				$pager->setDebug(false);
				$data['pick'] = $pager->paginate($cache,$sql2);
				
			
				if(!$data['pick']){
					echo json_encode(array('error'=>'Hết dữ liệu!'));
					exit();
				}

				echo json_encode(array('content'=>truyen_render_desktop_items($data['pick'])));
				
				break;
				
				case 'category':
				$cache=new cache;
				$_GET['page'] = (int) $_POST['page'];

				$cat=$array[2];
				
				if($array[3]=='pick'){
						$sql ="select truyen_id from truyen_theloai_fk  where theloai_id=".intval($cat)." and pick = 1 and duyet=1 order by time_update desc ";
						$sql2="select truyen_id from truyen_theloai_fk where theloai_id=".intval($cat)." and pick = 1 and duyet=1 ";
				}else
				if($array[3]=='moi'){
						$sql ="select truyen_id from truyen_theloai_fk  where  theloai_id=".intval($cat)." and duyet=1 order by time_upload desc ";
						$sql2="select truyen_id from truyen_theloai_fk where theloai_id=".intval($cat).' and duyet=1';
				}
				
				
			
				$pager = new Pagination2($sql,6, 4, '',0,'truyen_2');
				$pager->setDebug(false);
				$data['pick'] = $pager->paginate($cache,$sql2);
				
			
				if(!$data['pick']){
					echo json_encode(array('error'=>'Hết dữ liệu!'));
					exit();
				}

				echo json_encode(array('content'=>truyen_render_desktop_items($data['pick'])));
				break;
				
		
			
				
		}
		exit();

  ?>